package com.ihd.ihardware.view.tzc.health.view;

import android.os.Bundle;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.ihd.ihardware.R;
import com.ihd.ihardware.databinding.ActivitySolutionBinding;
import com.ihd.ihardware.view.tzc.health.viewmodel.SolutionViewModel;
import com.trello.rxlifecycle2.components.support.RxFragment;

import java.util.ArrayList;
import java.util.List;

import cn.wowjoy.commonlibrary.base.BaseActivity;
import cn.wowjoy.commonlibrary.base.BaseFragment;

public class SolutionActivity extends BaseActivity<ActivitySolutionBinding, SolutionViewModel> {
    private FragmentPagerAdapter mFragmentPagerAdapter;
    private List<BaseFragment> mFragment;

    @Override
    protected void init(Bundle savedInstanceState) {
        mImmersionBar.statusBarDarkFont(true).init();
        binding.mtitlebar.setTitle("饮食方案");
        binding.mtitlebar.setLeftBack(this);

        mFragment = new ArrayList<>();
        mFragment.add(SolutionFragment.newInstance(R.drawable.eatlist_1ssjy));
        mFragment.add(SolutionFragment.newInstance(R.drawable.eatlist_2rcsp));
        mFragment.add(SolutionFragment.newInstance(R.drawable.eatlist_3ydys));
        mFragment.add(SolutionFragment.newInstance(R.drawable.eatlist_4yycs));
        mFragmentPagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public RxFragment getItem(int position) {
                return mFragment.get(position);
            }

            @Override
            public int getCount() {
                return mFragment.size();
            }
        };
        binding.vp.setAdapter(mFragmentPagerAdapter);
        binding.vp.setOffscreenPageLimit(4);
        binding.vp.setCurrentItem(0);
        binding.vp.setCanScroll(true);

        binding.ssjyLL.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                binding.vp.setCurrentItem(0, true);
            }
        });

        binding.rcspLL.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                binding.vp.setCurrentItem(1, true);
            }
        });

        binding.ydysLL.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                binding.vp.setCurrentItem(2, true);
            }
        });

        binding.yycsLL.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                binding.vp.setCurrentItem(3, true);
            }
        });

        binding.vp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                selectPage(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    private void selectPage(int pos) {
        switch (pos) {
            case 0:
                binding.ssjyTV.setTextColor(getResources().getColor(R.color.C_32353B));
                binding.ssjyV.setVisibility(View.VISIBLE);
                binding.rcspTV.setTextColor(getResources().getColor(R.color.C_B5B7BF));
                binding.rcspV.setVisibility(View.INVISIBLE);
                binding.ydysTV.setTextColor(getResources().getColor(R.color.C_B5B7BF));
                binding.ydysV.setVisibility(View.INVISIBLE);
                binding.yycsTV.setTextColor(getResources().getColor(R.color.C_B5B7BF));
                binding.yycsV.setVisibility(View.INVISIBLE);
                break;
            case 1:
                binding.ssjyTV.setTextColor(getResources().getColor(R.color.C_B5B7BF));
                binding.ssjyV.setVisibility(View.INVISIBLE);
                binding.rcspTV.setTextColor(getResources().getColor(R.color.C_32353B));
                binding.rcspV.setVisibility(View.VISIBLE);
                binding.ydysTV.setTextColor(getResources().getColor(R.color.C_B5B7BF));
                binding.ydysV.setVisibility(View.INVISIBLE);
                binding.yycsTV.setTextColor(getResources().getColor(R.color.C_B5B7BF));
                binding.yycsV.setVisibility(View.INVISIBLE);
                break;
            case 2:
                binding.ssjyTV.setTextColor(getResources().getColor(R.color.C_B5B7BF));
                binding.ssjyV.setVisibility(View.INVISIBLE);
                binding.rcspTV.setTextColor(getResources().getColor(R.color.C_B5B7BF));
                binding.rcspV.setVisibility(View.INVISIBLE);
                binding.ydysTV.setTextColor(getResources().getColor(R.color.C_32353B));
                binding.ydysV.setVisibility(View.VISIBLE);
                binding.yycsTV.setTextColor(getResources().getColor(R.color.C_B5B7BF));
                binding.yycsV.setVisibility(View.INVISIBLE);
                break;
            case 3:
                binding.ssjyTV.setTextColor(getResources().getColor(R.color.C_B5B7BF));
                binding.ssjyV.setVisibility(View.INVISIBLE);
                binding.rcspTV.setTextColor(getResources().getColor(R.color.C_B5B7BF));
                binding.rcspV.setVisibility(View.INVISIBLE);
                binding.ydysTV.setTextColor(getResources().getColor(R.color.C_B5B7BF));
                binding.ydysV.setVisibility(View.INVISIBLE);
                binding.yycsTV.setTextColor(getResources().getColor(R.color.C_32353B));
                binding.yycsV.setVisibility(View.VISIBLE);
                break;
        }
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_solution;
    }

    @Override
    protected Class getViewModelClass() {
        return SolutionViewModel.class;
    }
}
